package com.xmj.web.controller.ms;

import com.xmj.common.annotation.Log;
import com.xmj.common.core.controller.BaseController;
import com.xmj.common.core.domain.AjaxResult;
import com.xmj.common.core.page.TableDataInfo;
import com.xmj.common.enums.BusinessType;
import com.xmj.common.utils.poi.ExcelUtil;
import com.xmj.ms.domain.BarberShopGoods;
import com.xmj.ms.service.IBarberShopGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存管理Controller
 *
 * @author ohh
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/ms/BarberShopGoods")
public class BarberShopGoodsController extends BaseController
{
    @Autowired
    private IBarberShopGoodsService barberShopGoodsService;

    /**
     * 查询库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('ms:BarberShopGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(BarberShopGoods barberShopGoods)
    {
        startPage();
        List<BarberShopGoods> list = barberShopGoodsService.selectBarberShopGoodsList(barberShopGoods);
        return getDataTable(list);
    }

    /**
     * 导出库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('ms:BarberShopGoods:export')")
    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BarberShopGoods barberShopGoods)
    {
        List<BarberShopGoods> list = barberShopGoodsService.selectBarberShopGoodsList(barberShopGoods);
        ExcelUtil<BarberShopGoods> util = new ExcelUtil<BarberShopGoods>(BarberShopGoods.class);
        util.exportExcel(response, list, "库存管理数据");
    }

    /**
     * 获取库存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ms:BarberShopGoods:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return success(barberShopGoodsService.selectBarberShopGoodsByGoodsId(goodsId));
    }

    /**
     * 新增库存管理
     */
    @PreAuthorize("@ss.hasPermi('ms:BarberShopGoods:add')")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BarberShopGoods barberShopGoods)
    {
        return toAjax(barberShopGoodsService.insertBarberShopGoods(barberShopGoods));
    }

    /**
     * 修改库存管理
     */
    @PreAuthorize("@ss.hasPermi('ms:BarberShopGoods:edit')")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BarberShopGoods barberShopGoods)
    {
        return toAjax(barberShopGoodsService.updateBarberShopGoods(barberShopGoods));
    }

    /**
     * 删除库存管理
     */
    @PreAuthorize("@ss.hasPermi('ms:BarberShopGoods:remove')")
    @Log(title = "库存管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(barberShopGoodsService.deleteBarberShopGoodsByGoodsIds(goodsIds));
    }
}
